package com.damie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dadie.Domain.ShopOrderDomain;
import com.dadie.Domain.ShopOrderProductDomain;
import com.dadie.Dto.ShopOrderProductDto;
import com.damie.mapper.ShopOrderProductMapper;
import com.damie.service.ShopOrderProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.damie.uilt.Copy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Alon
 * @since 2021-01-24
 */
@Service
public class ShopOrderProductServiceImpl extends ServiceImpl<ShopOrderProductMapper, ShopOrderProductDomain> implements ShopOrderProductService {

    @Resource
    private ShopOrderProductMapper mapper;

    @Override
    public List<ShopOrderProductDto> selectByOrderProduct(String id) {
        if (id!=null&&id!=""){
            QueryWrapper<ShopOrderProductDomain> shopOrderProductDomainQueryWrapper = new QueryWrapper<>();
            shopOrderProductDomainQueryWrapper.eq("shop_order_id",id);

            List<ShopOrderProductDomain> shopOrderProductDomains = mapper.selectList(shopOrderProductDomainQueryWrapper);
            List<ShopOrderProductDto> collect = shopOrderProductDomains.stream().map(shopOrderProductDomain -> {
                return (ShopOrderProductDto) Copy.copy(shopOrderProductDomain, new ShopOrderProductDto());
            }).collect(Collectors.toList());
            return collect;
        }
        throw new RuntimeException("参数异常");
    }
}
